/*******************************************************\
|* Author: Trevor Sundberg
\*******************************************************/

// Header protection
#pragma once
#ifndef SKUGO_FUNCTION_HELPERS_HPP
#define SKUGO_FUNCTION_HELPERS_HPP

namespace Skugo
{
  template <typename T>
  struct BindParameter
  {
    static T& Read(const RuntimePointer& pointer)
    {
      // Return a reference to the instance
      return *(T*)pointer.Instance;
    }
  };

  template <typename T>
  struct BindParameter<T&>
  {
    static T& Read(const RuntimePointer& pointer)
    {
      // Return a reference to the instance
      return *(T*)pointer.Instance;
    }
  };

  template <typename T>
  struct BindParameter<T*>
  {
    static T* Read(const RuntimePointer& pointer)
    {
      // Return the pointer to that instance
      return (T*)pointer.Instance;
    }
  };

  
  template <typename T>
  struct BindReturn
  {
    static void Write(const RuntimePointer& pointer, const T& value)
    {
      // Copy over the value itself
      *(T*)pointer.Instance = value;
    }
  };

  template <typename T>
  struct BindReturn<T&>
  {
    static void Write(const RuntimePointer& pointer, const T& value)
    {
      // Output a pointer to the object that is being referenced
      pointer.Instance = &value;
    }
  };

  template <typename T>
  struct BindReturn<T*>
  {
    static void Write(const RuntimePointer& pointer, const T* value)
    {
      // Output the pointer itself
      pointer.Instance = value;
    }
  };
}

// End header protection
#endif
